<template>
  <div id="app">
    <!-- Header -->
    <header class="header can-sticky">
      <el-row type="flex" justify="space-between" align="middle" class="container">
        <el-col :span="4">
          <div class="logo">
            <a href="/home">
              <img src="@/assets/images/logo.png" alt="logo" />
            </a>
          </div>
        </el-col>
        <el-col :span="16">
          <nav class="navigation">
            <ul class="main-menu">
              <li
                v-for="(item, index) in mainMenu"
                :key="index"
                class="menu-item"
                :class="{ 'menu-item-has-children': !!item.children }"
              >
                <a :href="item.href" @click="handleMenuClick(item, $event)">
                  {{ item.title }}
                </a>

                <!-- 二级菜单 -->
                <ul v-if="item.children" class="sub-menu">
                  <li
                    v-for="(child, childIdx) in item.children"
                    :key="childIdx"
                    class="menu-item"
                    :class="{ 'menu-item-has-children': !!child.children }"
                  >
                    <a :href="child.href" @click="handleMenuClick(child, $event)">
                      {{ child.title }}
                    </a>

                    <!-- 三级菜单 -->
                    <ul v-if="child.children" class="sub-menu">
                      <li
                        v-for="(grandChild, gIdx) in child.children"
                        :key="gIdx"
                        class="menu-item"
                      >
                        <a :href="grandChild.href">{{ grandChild.title }}</a>
                      </li>
                    </ul>
                  </li>
                </ul>
              </li>
            </ul>
          </nav>
        </el-col>
<!--        <el-col :span="4" class="text-right">-->
<!--          <a href="/login" class="header_btn thm-btn btn-rounded btn-small">Log In</a>-->
<!--        </el-col>-->
      </el-row>
    </header>

    <!-- Subheader  -->
    <div class="section-bg section-padding subheader">
      <el-container>
        <el-main>
          <div class="container">
            <el-row type="flex" justify="center">
              <el-col :span="24" class="text-center">
                <h1 class="text-white page-title">About Us</h1>
              </el-col>
            </el-row>
          </div>
        </el-main>
      </el-container>
    </div>

    <!-- About Section -->
    <section class="section-padding section about-section">
      <el-row :gutter="30" type="flex" align="middle" justify="center">
        <!-- 左侧：图片 -->
        <el-col :md="12" :sm="24" class="text-center-md text-left-sm">
          <div class="image-container mb-xl-30">
            <img
              v-if="aboutCase && aboutCase.coverImage"
              :src="fixImgUrl(aboutCase.coverImage)"
              alt="About Us"
              class="about-image shadow-lg rounded"
            />
          </div>
        </el-col>

        <!-- 右侧：内容 -->
        <el-col :md="12" :sm="24" class="px-md-4">
          <div class="about-content">
            <div class="section-header" v-if="aboutCase">
              <h1 class="title display-5 fw-bold">{{ aboutCase.title || 'No Title' }}</h1>
              <h3 class="subtitle h5 text-muted">{{ aboutCase.subtitle || 'No Subtitle' }}</h3>
<!--              <p class="content mt-3" v-html="aboutCase.content || '暂无内容'" ></p>-->
              <p class="content mt-3">{{ aboutCase.content || '暂无内容' }}</p>
            </div>
          </div>
        </el-col>
      </el-row>
    </section>
  </div>

</template>

<script>
import { listCases } from "@/api/achievement/cases"
export default {
  data() {
    return {
      casesList: [],
      totalCount: 0,
      mainMenu: [
        {
          title: '首页',
          href: '/home'
        },
        {
          title: '关于',
          href: '/about'
        },
        {
          title: '服务',
          href: '/services',
        },
        {
          title: '博客',
          href: '#',
          children: [
            {
              title: '博客网络',
              href: '#',
              children: [
                {title: '全宽', href: '/blog-grid'},
                {title: '左侧边栏', href: '/blog-grid-left'},
                {title: '右侧边栏', href: '/blog-grid-right'}
              ]
            },
          ]
        },
        {
          title: '联系我们',
          href: '/contact'
        }
      ]
    };
  },
  mounted() {
    this.fetchShowData(); // 加载组件时获取数据
  },
  computed: {
    // 从 casesList 中找出 type = 'about' 的那条数据
    aboutCase() {
      return this.casesList.find(item => item.type === 'about') || null;
    }
  },
  methods: {
    fixImgUrl(path) {
      if (!path) return '';
      return path.startsWith(process.env.VUE_APP_BASE_API) ? encodeURI(path) : encodeURI(process.env.VUE_APP_BASE_API + path);
    },
    async fetchShowData() {
      try {
        // 假设 showCases 现在正确获取列表
        const response = await listCases({
          // 根据实际 API 要求传参，比如分页
          pageNum: 1,
          pageSize: 10
        });
        console.log('API 响应:', response);

        // ✅ 安全检查：确保 response, response.data, response.data.rows 都存在
        if (response && response.rows) {
          this.casesList = Array.isArray(response.rows) ? response.rows : [response.rows];
          this.totalCount = response.total || 0;
          console.log('获取案例成功:', this.casesList);
        } else {
          console.warn('API 响应缺少必要的数据字段:', response);
          // this.casesList 和 this.totalCount 已经是初始值，无需再赋
        }

      } catch (error) {
        // ✅ 现在 catch 块是安全的，不会因为读取 undefined 而崩溃
        console.error('获取案例失败:', error);
        // 数据已在上面初始化，这里可以保持不变或再次重置
      }
    },
    handleMenuClick(item, event) {
      // 如果有子菜单，阻止跳转，用于展开/收起
      if (item.children) {
        event.preventDefault();
        // 可以在这里添加展开/收起逻辑（比如维护一个展开状态数组）
        console.log('Toggle submenu for:', item.title);
      }
      // 否则允许正常跳转
    }
  }
};
</script>

<style scoped>
/* 全局重置与字体 */
#app {
  font-family: 'Poppins', sans-serif;
  margin: 0;
  padding: 0;
}

/* 容器居中，类似 Bootstrap */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: border-box;
}

/* =============
   Header 样式
============= */
.header {
  background-color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  padding: 15px 0;
  position: relative;
  z-index: 1000;
}

.header.can-sticky {
  position: sticky;
  top: 0;
  transition: all 0.3s ease;
}

.logo img {
  height: 50px;
  transition: all 0.3s ease;
}

.logo img:hover {
  opacity: 0.9;
}

/* 导航栏 - 主菜单 */
.navigation {
  display: flex;
  justify-content: center;
}

.main-menu {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 30px;
  align-items: center;
}

.main-menu > .menu-item {
  position: relative;
}

.main-menu > .menu-item > a {
  text-decoration: none;
  color: #333;
  font-weight: 500;
  font-size: 16px;
  transition: color 0.3s ease;
  padding: 5px 0;
  display: block;
}

.main-menu > .menu-item > a:hover,
.main-menu > .menu-item > a.active {
  color: #0066ff;
}

/* 二级菜单 */
.sub-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: #fff;
  min-width: 200px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  list-style: none;
  margin: 0;
  padding: 10px 0;
  z-index: 1001;
}

.menu-item-has-children:hover > .sub-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.sub-menu .menu-item {
  padding: 0;
}

.sub-menu .menu-item > a {
  color: #555;
  padding: 10px 20px;
  font-size: 15px;
  display: block;
  transition: background 0.3s ease, color 0.3s ease;
}

.sub-menu .menu-item > a:hover {
  background-color: #f5f9ff;
  color: #0066ff;
  padding-left: 24px;
}

/* 三级菜单 */
.sub-menu .sub-menu {
  left: 100%;
  top: 5px;
}

/* 登录按钮 */
.header_btn {
  background-color: #0066ff;
  color: #fff !important;
  padding: 10px 20px;
  text-decoration: none;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.3s ease;
  display: inline-block;
  border: none;
  outline: none;
}

.header_btn:hover {
  background-color: #0052cc;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 102, 255, 0.3);
}

/* =============
   Subheader 样式
============= */
.subheader {
  background-image: url('https://images.unsplash.com/photo-1517694712202-14dd9538aa97?ixlib=rb-4.0.3&auto=format&fit=crop&w=1350&q=80');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  padding: 100px 0;
  color: #fff;
  position: relative;
}

.subheader::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6); /* 深色遮罩提升文字可读性 */
  z-index: 1;
}

.subheader .el-main {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-title {
  font-size: 3rem;
  font-weight: 700;
  margin: 0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  letter-spacing: -0.5px;
}

.text-white {
  color: #ffffff;
}

.text-center {
  text-align: center;
}

/* 整体区域 */
.about-section {
  background: #f9fbfd;
  padding: 80px 20px;
  position: relative;
  overflow: hidden;
}

/* 响应式文本对齐 */
.text-center-md {
  text-align: center;
}
.text-left-sm {
  text-align: left;
}

/* 图片容器 */
.image-container {
  display: flex;
  justify-content: center;
  margin: 0 auto;
  max-width: 100%;
}

.about-image {
  max-width: 100%;
  height: auto;
  border-radius: 12px !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12) !important;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.about-image:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.18);
}

/* 内容区 */
.about-content {
  padding: 20px 0;
  line-height: 1.7;
  color: #444;
}

.title {
  font-size: 2.2rem;
  color: #1a1a1a;
  line-height: 1.3;
  margin-bottom: 10px;
}

.subtitle {
  font-size: 1.2rem;
  color: #666;
  margin-bottom: 20px;
  font-weight: 400;
}

.content {
  line-height: 1.8;
  font-size: 1rem;
  color: #333;
}

.content * {
  margin: 0;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
}

.content h3, .content h4 {
  font-weight: bold;
  margin-bottom: 1em;
}

.content span {
  background-color: transparent !important;
  color: inherit !important;
}

/* 响应式优化 */
@media (max-width: 992px) {
  .about-section {
    padding: 60px 15px;
  }

  .title {
    font-size: 2rem;
  }

  .subtitle {
    font-size: 1.1rem;
  }
}

@media (max-width: 768px) {
  .about-image {
    max-width: 85%;
    margin: 0 auto;
  }

  .about-content {
    text-align: center;
  }

  .section-header {
    padding: 0 15px;
  }

  .title, .subtitle {
    text-align: center;
  }

  .content {
    text-align: justify;
  }
}

@media (max-width: 576px) {
  .about-image {
    max-width: 100%;
  }

  .title {
    font-size: 1.8rem;
  }

  .section-tagline {
    font-size: 12px;
  }
}

/* =============
   响应式设计
============= */
@media (max-width: 992px) {
  .main-menu {
    gap: 20px;
  }

  .page-title {
    font-size: 2.5rem;
  }
}

@media (max-width: 768px) {
  .header {
    padding: 12px 0;
  }

  .logo img {
    height: 40px;
  }

  .main-menu {
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .main-menu > .menu-item {
    font-size: 14px;
  }

  .sub-menu {
    min-width: 180px;
  }

  .sub-menu .menu-item > a {
    padding: 8px 16px;
    font-size: 14px;
  }

  .page-title {
    font-size: 2rem;
  }

  .container {
    padding: 0 15px;
  }
}

@media (max-width: 576px) {
  .main-menu {
    gap: 10px;
    font-size: 14px;
  }

  .header_btn {
    padding: 8px 16px;
    font-size: 13px;
  }

  .page-title {
    font-size: 1.8rem;
  }
}

</style>
